<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('pay_config')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <template slot="payStatus" slot-scope="text, record, index">
          <a-switch v-model="record.payStatus==1" checkedChildren="启用" unCheckedChildren="禁用" @change="(checked) => setStatus(checked,record)"/>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <!--<a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>-->
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <pay-config-modal ref="modalForm" @ok="modalFormOk"></pay-config-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { XuRuiListMixin } from '@/mixins/XuRuiListMixin'
  import PayConfigModal from './modules/PayConfigModal'
  import {payStatus} from '@/api/api'

  export default {
    name: 'PayConfigList',
    mixins:[XuRuiListMixin, mixinDevice],
    components: {
      PayConfigModal
    },
    data () {
      return {
        description: 'pay_config管理页面',
        // 表头
        columns: [
          /*{
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },*/
          {
            title:'logo',
            align:"center",
            dataIndex: 'payLogo',
            scopedSlots: {customRender: "imgSlot"}
          },
          {
            title:'支付名称',
            align:"center",
            dataIndex: 'payName'
          },
         /* {
            title:'编码',
            align:"center",
            dataIndex: 'payCode'
          },
          {
            title:'支付合作id,商户id，差不多是支付平台的账号或id',
            align:"center",
            dataIndex: 'partner'
          },*/
          {
            title:'AppID',
            align:"center",
            dataIndex: 'appId'
          },
          {
            title: '平台类型',
            align: 'center',
            dataIndex: 'platType_dictText'
          },
         /* {
            title:'支付平台公钥(签名校验使用)，sign_type只有单一key时public_key与private_key相等，比如sign_type=MD5(友店支付除外)的情况',
            align:"center",
            dataIndex: 'publicKey'
          },
          {
            title:'应用私钥(生成签名)',
            align:"center",
            dataIndex: 'privateKey'
          },
          {
            title:'异步回调地址',
            align:"center",
            dataIndex: 'notifyUrl'
          },
          {
            title:'同步回调地址',
            align:"center",
            dataIndex: 'returnUrl'
          },
          {
            title:'收款账号, 针对支付宝',
            align:"center",
            dataIndex: 'seller'
          },
          {
            title:'签名类型',
            align:"center",
            dataIndex: 'signType'
          },
          {
            title:'枚举值，字符编码 utf-8,gbk等等',
            align:"center",
            dataIndex: 'inputCharset'
          },
          {
            title:'支付类型,aliPay：支付宝，wxPay：微信, youdianPay: 友店微信,此处开发者自定义对应com.egzosn.pay.demo.entity.PayType枚举值',
            align:"center",
            dataIndex: 'payType'
          },
          {
            title:'消息类型，text,xml,json',
            align:"center",
            dataIndex: 'msgType'
          },
          {
            title:'请求证书地址，请使用绝对路径',
            align:"center",
            dataIndex: 'keystorePath'
          },
          {
            title:'证书对应的密码',
            align:"center",
            dataIndex: 'storePassword'
          },*/
          /*{
            title:'是否为测试环境',
            align:"center",
            dataIndex: 'isTest'
          },*/
          {
            title:'是否启用',
            align:"center",
            dataIndex: 'payStatus_dictText',
            scopedSlots: {customRender: "payStatus"}
          },
          /*{
            title:'applinks',
            align:"center",
            dataIndex: 'applinks'
          },*/

          /*{
            title:'乐观锁',
            align:"center",
            dataIndex: 'revision'
          },
          {
            title:'是否删除(0未删除 1已删除)',
            align:"center",
            dataIndex: 'deleted'
          },*/
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/pay/payConfig/list",
          delete: "/pay/payConfig/delete",
          deleteBatch: "/pay/payConfig/deleteBatch",
          setPayStatus:"/pay/payConfig/setPayStatus",
          exportXlsUrl: "/pay/payConfig/exportXls",
          importExcelUrl: "pay/payConfig/importExcel",
          
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'payName',text:'账户名称'})
        fieldList.push({type:'string',value:'payCode',text:'编码'})
        fieldList.push({type:'string',value:'partner',text:'支付合作id,商户id，差不多是支付平台的账号或id'})
        fieldList.push({type:'string',value:'appId',text:'应用id'})
        fieldList.push({type:'string',value:'publicKey',text:'支付平台公钥(签名校验使用)，sign_type只有单一key时public_key与private_key相等，比如sign_type=MD5(友店支付除外)的情况'})
        fieldList.push({type:'string',value:'privateKey',text:'应用私钥(生成签名)'})
        fieldList.push({type:'string',value:'notifyUrl',text:'异步回调地址'})
        fieldList.push({type:'string',value:'returnUrl',text:'同步回调地址'})
        fieldList.push({type:'string',value:'seller',text:'收款账号, 针对支付宝'})
        fieldList.push({type:'string',value:'signType',text:'签名类型'})
        fieldList.push({type:'string',value:'inputCharset',text:'枚举值，字符编码 utf-8,gbk等等'})
        fieldList.push({type:'string',value:'payType',text:'支付类型,aliPay：支付宝，wxPay：微信, youdianPay: 友店微信,此处开发者自定义对应com.egzosn.pay.demo.entity.PayType枚举值'})
        fieldList.push({type:'string',value:'msgType',text:'消息类型，text,xml,json'})
        fieldList.push({type:'string',value:'keystorePath',text:'请求证书地址，请使用绝对路径'})
        fieldList.push({type:'string',value:'storePassword',text:'证书对应的密码'})
        fieldList.push({type:'int',value:'isTest',text:'是否为测试环境'})
        fieldList.push({type:'int',value:'payStatus',text:'是否启用'})
        fieldList.push({type:'string',value:'applinks',text:'applinks'})
        fieldList.push({type:'string',value:'payLogo',text:'logo'})
        fieldList.push({type:'string',value:'revision',text:'乐观锁'})
        fieldList.push({type:'int',value:'deleted',text:'是否删除(0未删除 1已删除)'})
        this.superFieldList = fieldList
      },
      setStatus (check, record) {
        debugger
        let that = this;
        payStatus({ids: record.id, payStatus: Number(check)}).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            that.loadData();
          } else {
            that.$message.warning(res.message);
          }
        });
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>